Hello everyone! =) I need some help in this case:
Code:
#include <stdio.h>
#include <stdlib.h>
potenzieren(float basis, int exponent){
int i;
float ergebnis = basis;
for(i=1;i<=exponent;i++)
ergebnis*=basis;
return ergebnis;
}
main (int argc,char *argv[]){
if (argc==2){
if (strcmp(argv[1],"-help")||strcmp(argv[1],"--help")||strcmp(argv[1],"help")){
/*showtooltip*/
printf("You can use this programm to calculate simple formulas step by step.\n Operators you can use are:\n'+'\t\t for addition\n'-'\t\t for subtraction\n'*' \t\t for multiplying\n'/'\t\t for division\n'^'\t\t for exponential formulas\n'from'\t\t to get the chance of\n\t\t getting [x] right from [y]amount\n");
}
}
if (argc<4){
printf("Use calculator '[number] [operator] [number]' to get a result!\n");
exit(1);
}
float z;
if (argc==4){
float x = atof(argv[1]);
float y = atof(argv[3]);
switch (argv[2][0]){
case '+':
z=x+y;
break;
case '-':
z=x-y;
break;
case '/':
z=x/y;
break;
case '*' : //42 = '*' ASCII
z=x*y;
break;
case '^':
z=potenzieren(x,y);
break;
default : printf("Wrong operator!\n");
break;
}
printf("%s %s %s = %f \n",argv[1], argv[2], argv[3], z);
}
exit(0);
}
Everything works right, should only be a simple programm to make easy calculations... But multiplying will not work correctly. =(
I don't know why, I even tried entering 42 as binary code, but won't work...
Some help? =)
Greets